using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPProductsService 
    {
        ISession session;
        public MRPProductsService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public MRPProductsService(ISession session)
        {
            this.session = session;
        }

        public void InsertMrpproducts(MRPProducts mrpproductsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpproductsX);
            tx.Commit();
        }

        public void UpdateMrpproducts(MRPProducts mrpproductsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpproductsX);
            tx.Commit();
        }

        public void DeleteMrpproducts(MRPProducts mrpproductsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpproductsX);
            tx.Commit();
        }

        public IList<MRPProducts> GetAllMrpproducts(Boolean evict)
        {



            IQuery query = session.CreateQuery("select p from MRPProducts p");
            IList<MRPProducts> list = query.List<MRPProducts>();
            if (evict)
            {
                foreach (MRPProducts s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPProducts GetAllMrpproductsByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPProducts as c where c.Productcode= :x");
            query.SetString("x", id);
            MRPProducts s = (MRPProducts)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPProducts> GetMrpproductsByQuery(IQuery query,Boolean evict)
        {
            IList<MRPProducts> list = query.List<MRPProducts>();
            if (evict)
            {
                foreach (MRPProducts s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
